function swimming() {}
swimming.runFrame = 0;
swimming.swmmingtimer = null;
swimming.percent = 0;
swimming.reverCount = 0;
swimming.reverTimer = null;
swimming.counttime = 3;
swimming.time = 20; //总计20秒
swimming.meter = 0; //
swimming.timer = null;
swimming.hit = false;
swimming.hitmeter = 1; //每点击一下游得距离
swimming.hittimer = null;
swimming.audioPlayer = null;
swimming.isend = false;
//开始
swimming.start = function() {
	swimming.time = 20;
	swimming.meter = 0;
	var allTime = swimming.time;
	$("#mask").hide();
	$("#time").html(swimming.time);
	$("#length").html(swimming.meter);
	$("#result").hide();
	swimming.isend = false;
	swimming.timer = setInterval(function() {
		swimming.time--;
		if (swimming.time == 0) {
			swimming.end();
			swimming.isend = true;
			if(swimming.timer) clearInterval(swimming.timer);
		}
			$("#time").html(swimming.time);
			var cut = swimming.time / allTime;
			$("#pg").width(cut * 100 + "%");
		
	}, 1000);
	$("#running_handler").unbind("touchend");
	$("#running_handler").bind("touchend", function() {
		if (swimming.isend) return;
		if (swimming.hittimer) {
			clearTimeout(swimming.hittimer);
			swimming.hittimer = null;
		}
		swimming.hit = true;
		swimming.checkhit();
		swimming.meter = swimming.meter + swimming.hitmeter;
		$("#length").html(swimming.meter);
	});

};
swimming.checkhit = function() {
	if (!swimming.hit) { //暂停敲击停止游泳
		swimming.stop();
	} else {
		swimming.run();
		swimming.hittimer = setTimeout(function() {
			if (swimming.hittimer) {
				clearTimeout(swimming.hittimer);
				swimming.hittimer = null;
			}
			swimming.hit = false;
			swimming.checkhit();
		}, 500); //五百毫秒后还未敲击停止游泳
	}
};
//结束
swimming.end = function() {
	if (swimming.timer) {
		clearInterval(swimming.timer);
		swimming.timer = null;
	}
	if (swimming.swmmingtimer) {
		clearInterval(swimming.swmmingtimer);
		swimming.swmmingtimer = null;
	}
	if (swimming.reverTimer) {
		clearInterval(swimming.reverTimer);
		swimming.reverTimer = null;
	}
	$("#result").show();
	$("#allLength").html(swimming.meter);
};
swimming.run = function() {
	if ($(".run_con").hasClass("run")) return;

	$(".run_con").addClass("run");
	if (swimming.timer) {
		clearInterval(swimming.swmmingtimer);
		swimming.swmmingtimer = null;
	}
	swimming.swmmingtimer = setInterval(function() {
		swimming.runFrame++;
		var frame = swimming.runFrame;
		if (frame > 2) {
			frame = 0;
			swimming.runFrame = 0;
		}
		var top = frame * 50;
		$(".running_person").css("background-position-y", top + "%");
	}, 100);
	swimming.nextRever();
	if (!swimming.audioPlayer) {
		swimming.audioPlayer = new _mu.Player({
			// baseDir是必填初始化参数，指向MuPlayer静态资源目录
			baseDir: 'muplayer-0.9.2/dist',
			mode: "list"
		});
		swimming.audioPlayer.reset();
		swimming.audioPlayer.setCur('css/image/1.mp3'); //.play();
		swimming.audioPlayer.play();

	} else {
		swimming.audioPlayer.play();
	}
};
swimming.nextRever = function() {
	swimming.reverCount++
		var bw = 2.558 * $(window).height();
	bw = swimming.reverCount * bw;
	$(".run_con").css("background-position-x", -bw + "px");
	swimming.reverTimer = setTimeout(function() {
		swimming.nextRever();
	}, 28000);
};
swimming.stop = function() {
	swimming.audioPlayer.pause();
	if (swimming.swmmingtimer) {
		clearInterval(swimming.swmmingtimer);
		swimming.timer = null;
	}
	var px = parseFloat($(".run_con").css("background-position-x"));
	$(".run_con").css("background-position-x", px + "px");
	$(".run_con").removeClass("run");
	if (swimming.reverTimer) {
		clearTimeout(swimming.reverTimer);
		swimming.reverTimer = null;
	}

};
swimming.countdown = function() {
	$("#countdown").html(swimming.counttime);
	swimming.counttime--;
	setTimeout(function() {
		if (swimming.counttime == 0) {
			swimming.start();
			//swimming.run();
		} else {
			swimming.countdown();
		}
	}, 1000)
};

$(function() {
	var wwidth = $(window).width();
	
});